package com.qsl.ssyx.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.sys.mapper.RegionMapper;
import com.qsl.ssyx.model.sys.Region;
import com.qsl.ssyx.sys.service.RegionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.ssyx.vo.sys.RegionVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 地区表 服务实现类
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-08
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements RegionService {

    //    条件分页查询
    @Override
    public IPage<Region> selectPage(Page<Region> pageParam, RegionVo regionVo) {
        LambdaQueryWrapper<Region> lqw = new LambdaQueryWrapper<>();

        if (!StringUtils.isEmpty(regionVo.getRegionName())) {
            lqw.like(Region::getName, regionVo.getRegionName().trim());
        }
        lqw.orderByDesc(Region::getId);// 倒序排序
        Page<Region> regionPage = baseMapper.selectPage(pageParam, lqw);

        return regionPage;
    }

    //    根据地区名称查询
    @Override
    public List<Region> findRegionByKeyword(String keyword) {
        LambdaQueryWrapper<Region> lqw = new LambdaQueryWrapper<>();

        if (!StringUtils.isEmpty(keyword)) {
            lqw.like(Region::getName, keyword);
        }
        List<Region> regions = baseMapper.selectList(lqw);
        return regions;
    }
}
